package com.future.orm.util;

import java.io.IOException;
import java.io.InputStream;

/**
 * 资源访问
 *
 * @author shiyong
 * 2020/5/16 17:10
 */
public class Resources {

    /**
     * 将文件以流的形式加载到内存中
     *
     * @param filePath 文件路径
     * @return java.io.InputStream
     * @author shiyong
     * 2020/5/16 17:14
    */
    public static InputStream getResourceAsStream(String filePath) throws IOException {
        InputStream in = Resources.class.getResourceAsStream(filePath);

        if (in == null) {
            throw new IOException("加载文件失败，filePath=" + filePath);
        }

        return in;
    }

    public static void main(String[] args) {
        String mapperConfig = "/MapperConfig.xml";
        try {
            InputStream in = getResourceAsStream(mapperConfig);

            System.out.println("加载成功");
        } catch (IOException e) {
            e.printStackTrace();

            System.out.println("加载失败");
        }


    }
}
